/*
package tests;

import static org.junit.Assert.*;

import java.util.logging.Level;
import java.util.logging.Logger;

import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;

import ownserver.Ship;
import ownserver.Turret;

import base.Arc;

import com.sun.sgs.app.AppContext;
import com.sun.sgs.app.DataManager;
import com.sun.sgs.app.ManagedReference;
import com.sun.sgs.auth.Identity;
import com.sun.sgs.kernel.TransactionScheduler;
import com.sun.sgs.service.DataService;
import com.sun.sgs.test.util.SgsTestNode;
import com.sun.sgs.test.util.TestAbstractKernelRunnable;

public class TurretTest {

	private static SgsTestNode serverNode;
	
    private static TransactionScheduler txnScheduler;
    private static Identity taskOwner;
    
    private static final String NAME = "TurretTest";
    
    private static double errorLimit = 1E-12;
	
    private static final Logger logger =
            Logger.getLogger(TurretTest.class.getName());
    
	@BeforeClass
	public static void setUpBeforeClass() throws Exception {
		serverNode = new SgsTestNode(NAME, null, null);
        
        
        txnScheduler = serverNode.getSystemRegistry().
                getComponent(TransactionScheduler.class);
        taskOwner = serverNode.getProxy().getCurrentOwner();
	}

	@AfterClass
	public static void tearDownAfterClass() throws Exception {
		serverNode.shutdown(true);
	}

	@Test
	public void testConstructor() throws Exception {
		txnScheduler.runTask(
				new TestAbstractKernelRunnable() {
				public void run() throws Exception {
					Ship s = new Ship(0, 0, 0, 0, null, 0);
					
					DataManager dataManager = AppContext.getDataManager();
			        
			        ManagedReference<Ship> shipRef = dataManager.createReference(s);
					
			        Turret t = new Turret(shipRef, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
				}
				}, taskOwner);
	}

	@Test
	public void testGetBeginAngle() throws Exception{
		txnScheduler.runTask(
				new TestAbstractKernelRunnable() {
				public void run() throws Exception {
					Ship s = new Ship(0, 0, 0, 0, null, 0);
					
					DataManager dataManager = AppContext.getDataManager();
			        
			        ManagedReference<Ship> shipRef = dataManager.createReference(s);
					
			        Turret t = new Turret(shipRef, 13, 0, 0, 0, 0, 0 ,0, 0, 0, 0);
			        
			        assertTrue(t.getBeginAngle() == 13);
			        
			        // non-0 heading
			        s.setHeading(30);
			        assertTrue(t.getBeginAngle() == 30+13);
				}
				}, taskOwner);
	}

	@Test
	public void testGetEndAngle() throws Exception {
		txnScheduler.runTask(
				new TestAbstractKernelRunnable() {
				public void run() throws Exception {
					Ship s = new Ship(0, 0, 0, 0, null, 0);
					
					DataManager dataManager = AppContext.getDataManager();
			        
			        ManagedReference<Ship> shipRef = dataManager.createReference(s);
					
			        Turret t = new Turret(shipRef, 13, 26, 0, 0, 0, 0, 0, 0, 0, 0);
			        
			        assertTrue(t.getEndAngle() == 26);
			        
			        // non-0 heading
			        s.setHeading(30);
			        assertTrue(t.getEndAngle() == 30+26);
				}
				}, taskOwner);
	}

	@Test
	public void testGetArc() throws Exception {
		txnScheduler.runTask(
				new TestAbstractKernelRunnable() {
				public void run() throws Exception {
					// 0 heading
					Ship s = new Ship(0, 0, 0, 0, null, 0);
					
					DataManager dataManager = AppContext.getDataManager();
			        
			        ManagedReference<Ship> shipRef = dataManager.createReference(s);
					
			        Turret t = new Turret(shipRef, 13, 26, 0, 0, 0, 0, 0, 0, 0, 0);
			        
			        Arc a = t.getArc();
			        
			        assertTrue(a.beginAngle == 13);
			        assertTrue(a.endAngle == 26);
			        
			        // non-0 heading
			        s.setHeading(30);
					
					a = t.getArc();
			        
			        assertTrue(a.beginAngle == 30+13);
			        assertTrue(a.endAngle == 30+26);
				}
				}, taskOwner);
	}

	@Test
	public void testGetX() throws Exception {
		txnScheduler.runTask(
				new TestAbstractKernelRunnable() {
				public void run() throws Exception {
					Ship s = new Ship(0, 0, 0, 0, null, 0);
					
					DataManager dataManager = AppContext.getDataManager();
			        
			        ManagedReference<Ship> shipRef = dataManager.createReference(s);
					
			        Turret t = new Turret(shipRef, 0, 0, 10, 0, 0, 0,0, 0, 0, 0);
			        
			        assertTrue(t.getX() == 10);
			        
			        // non-zero heading 
			        s.setHeading(30);
			        double rad = Math.toRadians(30);
			        closeEnough(t.getX(), 10 * Math.cos(rad));
			        
			        s.setX(100);
			        closeEnough(t.getX(), 100 + 10 * Math.cos(rad));
			        
			        t = new Turret(shipRef, 0, 0, 10, -30, 0, 0, 0, 0, 0, 0);
			        closeEnough(t.getX(), 100 + 10 * Math.cos(rad) - (-30) * Math.sin(rad));
				}
				}, taskOwner);
	}

	@Test
	public void testGetY() throws Exception {
		txnScheduler.runTask(
				new TestAbstractKernelRunnable() {
				public void run() throws Exception {
					Ship s = new Ship(0, 0, 0, 0, null, 0);
					s.setHeading(90);
					
					DataManager dataManager = AppContext.getDataManager();
			        
			        ManagedReference<Ship> shipRef = dataManager.createReference(s);
					
			        Turret t = new Turret(shipRef, 0, 0, 0, 10, 0, 0, 0, 0, 0, 0);
			        
			        closeEnough(t.getY(), 10);
			        
			        // non-zero heading 
			        s.setHeading(30);
			        double rad = Math.toRadians(30);
			        closeEnough(t.getY(), 10 * Math.sin(rad));
			        
			        s.setY(100);
			        closeEnough(t.getY(), 100 + 10 * Math.sin(rad));
			        
			        t = new Turret(shipRef, 0, 0, 10, -30, 0, 0, 0, 0, 0, 0);
			        closeEnough(t.getY(), 100 + -30 * Math.sin(rad) + 10 * Math.cos(rad));
				}
				}, taskOwner);
	}
	
	public void closeEnough(double a, double b)
	{
		if (Math.abs(a-b) < errorLimit == false)
		{
			logger.log(Level.INFO, "Not close enough: {0} vs {1}",
		            new Object[] {a,b});
		}
		assertTrue(Math.abs(a-b) < errorLimit);
	}

}
*/